package club.dataresources.service.impl;

import club.dataresources.entity.ServiceExample;
import club.dataresources.mapper.ServiceMapper;
import club.dataresources.service.ServiceService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @author
 * @create 2018-11-04 20:50
 **/
@Service
public class ServiceServiceImpl implements ServiceService {
    @Autowired
    private ServiceMapper serviceMapper;

    @Override
    public boolean addService(club.dataresources.entity.Service service) throws Exception {
        return serviceMapper.insertSelective(service)==1;
    }

    @Override
    public boolean removeService(Integer serviceId) throws Exception {
        return serviceMapper.deleteByPrimaryKey(serviceId)==1;
    }

    @Override
    public boolean updateService(club.dataresources.entity.Service service) throws Exception {
        return serviceMapper.updateByPrimaryKeySelective(service)==1;
    }

    @Override
    public club.dataresources.entity.Service findSerBySerId(Integer serviceId) throws Exception {
        return serviceMapper.selectByPrimaryKey(serviceId);
    }

    @Override
    public Page<club.dataresources.entity.Service> listService(Integer page, Integer rows, club.dataresources.entity.Service service) throws Exception {
        PageHelper.startPage(page, rows);
        ServiceExample example = new ServiceExample();
        ServiceExample.Criteria criteria = example.createCriteria();

        //如果是模糊查询
        if(service.getServiceName()!=null){
            criteria.andServiceNameLike(service.getServiceName());
        }
        criteria.andServiceIdIsNotNull();
        return serviceMapper.selectByExample(example);
    }
}
